home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 6.9 KB | 319 lines | [TEXT/MMCC] |
- /* ---------------------------------------------------------------------------
-
- menuHandler.c
-
- Copyright (c) 1995-6 Adobe Systems Incorporated
- All Rights Reserved
-
- --------------------------------------------------------------------------- */
-
- // Apple Includes
- #include <QDOffScreen.h>
- #include <Quickdraw.h>
- #include <QuickTimeComponents.h>
- #include <Dialogs.h>
-
- // Adobe includes
- #define __USING_QUICKTIME__
- #include "common.h"
- #include "menuHandler.h"
- #include "aimenugroups.h"
-
- #include "raster utils.h"
-
-
-
- // defines
- #define digitizerDepth 16
-
- #define kCaptureDialog 16001
- #define kSettingsItem 3
- #define kImageItem 4
-
- // variables
- SeqGrabComponent theSG;
- SGChannel theVideoChannel;
- GWorldPtr offScreenGWorldPtr;
- PixMapHandle offScreenPMH;
- Rect offScreenVideoRect = {0, 0, 120, 160};
-
- WindowPtr videoWindow;
-
-
-
- //functions
- Boolean doCaptureDialog( GWorldPtr capturedWorld );
- pascal Boolean captureFilterProc(DialogPtr theDialog, EventRecord * theEvent,
- short * itemHit, long refCon);
- OSErr updateImage( DialogPtr theDialog );
- OSErr SetupVideo(void);
- pascal Boolean SeqGrabberModalFilterProc(DialogPtr theDialog, EventRecord * theEvent,
- short * itemHit, long refCon);
-
-
- // implementation
-
- extern FXErr goMenuItem( AIMenuMessage *message ) {
-
- FXErr error = kNoErr;
- Boolean canceled;
-
- if ( message->menuItem == g->quickcamMenu ) {
- Rect rasterRect = { 0, 0, 240, 320 };
- GWorldPtr capturedWorld;
-
- createOffscreen( &capturedWorld, &rasterRect, 32 );
-
- canceled = doCaptureDialog( capturedWorld );
-
- if ( !canceled ) {
- AIArtHandle newRaster;
- MakeGWorldTileRequest request;
-
- // This creates NewArt(kRasterArt...) based on the GWorld supplied.
- error = newRasterArtForGWorld( capturedWorld, _ShortToFixed(72), &request, &newRaster );
- if (error)
- goto error;
-
- // This sets up all the copy information to copy from a GWorld to RasterArt
- CreateGWorldTile( &request );
-
- // Based on the above two calls, this will copy the GWorld pixels to the RasterArt
- error = copyGWorldToRasterArt( &request, newRaster );
-
- if ( error ) {
- if ( newRaster )
- sArt->DisposeArt( newRaster );
- }
- }
- disposeOffscreen( &capturedWorld );
- }
-
- error:
- return error;
-
- }
-
-
- Boolean doCaptureDialog( GWorldPtr capturedWorld ) {
- Rect box;
- short item_type;
- Handle pictHandle;
- short hit= ok;
-
- ModalFilterUPP captureFilter = NewModalFilterProc(captureFilterProc);
- DialogPtr dialog = GetNewDialog( 16001, nil, (WindowPtr) -1 );
-
- if ( dialog ) {
-
- do {
- ModalDialog( captureFilter, &hit);
- if (hit == kSettingsItem ) {
- SGModalFilterUPP settingsFilter = NewSGModalFilterProc(SeqGrabberModalFilterProc);
-
- SGSettingsDialog(theSG, theVideoChannel, 0, nil, 0,
- settingsFilter, 0);
-
- DisposeRoutineDescriptor (settingsFilter);
- }
-
- } while ((hit != ok) && (hit != cancel));
- }
-
- DisposeRoutineDescriptor (captureFilter);
-
- if ( hit == ok ) {
- PixMapHandle pmHandle = GetGWorldPixMap(capturedWorld);;
-
- // grab the capture frame before getting rid of the dialog
- GetDItem( dialog, kImageItem, &item_type, &pictHandle, &box );
-
- CopyBits( &dialog->portBits, (BitMapPtr)*pmHandle,
- &box, &capturedWorld->portRect, srcCopy + ditherCopy, nil);
- }
-
- DisposeDialog(dialog);
-
- return ( hit == cancel );
- }
-
- pascal Boolean captureFilterProc(DialogPtr theDialog, EventRecord * theEvent,
- short * itemHit, long refCon)
- {
- Boolean handled = false;
-
- handled = CallModalFilterProc(sMacUser->ModalFilterProc, theDialog, theEvent, itemHit );
-
- if ( !handled ) {
- updateImage( theDialog );
- }
-
- return handled;
- }
-
-
-
- OSErr updateImage( DialogPtr theDialog )
- {
- OSErr result;
-
- result = SGIdle(theSG);
- if ( !result )
- {
- RGBColor origForeColor, origBackColor;
- GrafPtr origPort;
- Rect box;
- short item_type;
- Handle pictHandle;
-
- RGBColor black = { 0x0000, 0x0000, 0x0000 };
- RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF };
-
- GetForeColor( &origForeColor);
- GetBackColor( &origBackColor);
- RGBForeColor(&black);
- RGBBackColor(&white);
- LockPixels(offScreenPMH);
-
- GetDItem( theDialog, kImageItem, &item_type, &pictHandle, &box );
-
- CopyBits((BitMapPtr)*offScreenPMH, &theDialog->portBits,
- &offScreenVideoRect, &box, srcCopy + ditherCopy, nil);
-
- UnlockPixels(offScreenPMH);
- RGBForeColor(&origForeColor);
- RGBBackColor(&origBackColor);
-
- // SetPort ( origPort );
- }
-
- return result;
- }
-
-
-
-
- OSErr InitializeVideo(void)
- {
- OSErr result;
-
- EnterMovies();
- result = SetupVideo();
- if ( result )
- return result;
-
- return noErr;
- }
-
- void CloseVideo(void)
- {
- if (theVideoChannel != nil)
- {
- SGDisposeChannel(theSG, theVideoChannel);
- theVideoChannel = nil;
- }
- if (theSG != nil)
- {
- CloseComponent(theSG);
- theSG = nil;
- }
- if (offScreenGWorldPtr != nil)
- {
- DisposeGWorld(offScreenGWorldPtr);
- offScreenGWorldPtr = nil;
- }
- }
-
- OSErr SetupVideo(void)
- {
- OSErr result = noErr;
-
- theSG = OpenDefaultComponent(SeqGrabComponentType, 0);
- if (theSG != nil)
- {
- result = SGInitialize(theSG);
- if ( !result )
- {
- result = SGNewChannel(theSG, VideoMediaType, &theVideoChannel);
- if ( !result )
- {
- CTabHandle cTable;
-
- result = SGGetSrcVideoBounds( theVideoChannel, &offScreenVideoRect );
- if ( !result )
- {
- cTable = digitizerDepth != 16 && digitizerDepth != 32 ? GetCTable(digitizerDepth) : nil;
- result = NewGWorld(&offScreenGWorldPtr, digitizerDepth, &offScreenVideoRect, cTable, nil, keepLocal);
- if ( cTable )
- DisposeCTable( cTable );
- if ( !result )
- {
- offScreenPMH = GetGWorldPixMap( offScreenGWorldPtr );
- LockPixels( offScreenPMH );
- result = SGSetGWorld(theSG, offScreenGWorldPtr, nil);
- if ( !result )
- {
- result = SGSetChannelUsage(theVideoChannel, seqGrabPreview);
- if ( !result )
- {
- result = SGSetUseScreenBuffer(theVideoChannel, true);
- if ( !result )
- {
- result = SGSetChannelBounds(theVideoChannel, &offScreenVideoRect);
- if ( !result )
- {
- result = SGSetVideoRect(theVideoChannel, &offScreenVideoRect);
- if ( !result )
- result = SGStartPreview(theSG);
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- return result;
- }
-
-
-
- //------------------------------
- //------------------------------
-
-
- pascal Boolean SeqGrabberModalFilterProc(DialogPtr theDialog, EventRecord * theEvent,
- short * itemHit, long refCon)
- {
- Boolean handled = false;
-
- (void)theDialog;
- if (theEvent->what == updateEvt && (WindowPtr)theEvent->message == (WindowPtr)refCon)
- {
- handled = true;
- }
- return handled;
- }
-
- //------------------------------
- //------------------------------
-
- extern FXErr addMyMenus( AIMenuMessage *message ) {
-
- FXErr error = kNoErr;
- PlatformAddMenuItemData throwAwayMenuData;
-
- throwAwayMenuData.groupName = kPlaceMenuGroup;
- throwAwayMenuData.itemText = g->menuText;
-
- error = sMenu->AddMenuItem( message->d.self, "quickcamHost", &throwAwayMenuData,
- 0, &g->quickcamMenu );
-
- if ( error )
- goto error;
-
- error:
- return error;
- }